<?php

namespace App\Services;

use App\Entity\UserEntity;
use App\Entity\WechatUserEntity;
use App\Models\WechatUser as WechatUserModel;

class UserCenterService
{
    public static function getUserInfo(UserEntity $userEntity)
    {
        $userInfo = $userEntity->toArray();
        $userInfo['headimgurl'] = $userInfo['nickname'] = '';
        $wechatUserModel = WechatUserModel::where('openid', $userEntity->getOpenid())->first();
        if ($wechatUserModel) {
            $wechatUserEntity = new WechatUserEntity($wechatUserModel);
            $userInfo['headimgurl'] = $wechatUserEntity->getHeadimgurl();
            $userInfo['nickname'] = $wechatUserEntity->getNickname();
        }
        return $userInfo;
    }
}
